{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "e623d28e",
   "metadata": {},
   "source": [
    "## 1. APP 币本位合约交易账户函数总览"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4ebd4c8a",
   "metadata": {},
   "source": [
    "|方法|解释|\n",
    "|:---|:---|\n",
    "|get_account|获取账户信息|\n",
    "|get_balance|获取单个产品余额|\n",
    "|get_balances|获取全部产品余额（列表格式）|\n",
    "|get_balancesMap|获取全部产品余额（字典格式）|\n",
    "|set_leverage|调整开仓杠杆|\n",
    "|set_marginType|更改持仓模式|\n",
    "|get_position|获取单个产品的持仓信息|\n",
    "|get_positions|获取全部产品的持仓信息（列表格式）|\n",
    "|get_positionsMap|获取全部产品的持仓信息字典（字典格式）|"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "42e13a5d",
   "metadata": {},
   "source": [
    "## 2. 模型实例化"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "52500912",
   "metadata": {},
   "outputs": [],
   "source": [
    "from binance_interface.app import BinanceCM\n",
    "from binance_interface.app.utils import eprint"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "271d5483",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 转发：需搭建转发服务器，可参考：https://github.com/pyted/binance_resender\n",
    "proxy_host = None\n",
    "key = 'xxxx'\n",
    "secret = 'xxxx'\n",
    "\n",
    "binanceCM = BinanceCM(\n",
    "    key=key, secret=secret,\n",
    "    proxy_host=proxy_host\n",
    ")\n",
    "account = binanceCM.account"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1e38f833",
   "metadata": {},
   "source": [
    "## 3. 获取账户信息 get_account"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "de298a87",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'code': 200,\n",
      " 'data': {'feeTier': 0,\n",
      "          'canTrade': True,\n",
      "          'canDeposit': True,\n",
      "          'canWithdraw': True,\n",
      "          'updateTime': 0,\n",
      "          'assets': [{'asset': 'ADA',\n",
      "                      'walletBalance': '0.00000000',\n",
      "                      'unrealizedProfit': '0.00000000',\n",
      "                      'marginBalance': '0.00000000',\n",
      "                      'maintMargin': '0.00000000',\n",
      "                      '...': '......'},\n",
      "                     {'asset': 'ALGO',\n",
      "                      'walletBalance': '0.00000000',\n",
      "                      'unrealizedProfit': '0.00000000',\n",
      "                      'marginBalance': '0.00000000',\n",
      "                      'maintMargin': '0.00000000',\n",
      "                      '...': '......'},\n",
      "                     {'asset': 'KNC',\n",
      "                      'walletBalance': '0.00000000',\n",
      "                      'unrealizedProfit': '0.00000000',\n",
      "                      'marginBalance': '0.00000000',\n",
      "                      'maintMargin': '0.00000000',\n",
      "                      '...': '......'},\n",
      "                     {'asset': 'CHZ',\n",
      "                      'walletBalance': '0.00000000',\n",
      "                      'unrealizedProfit': '0.00000000',\n",
      "                      'marginBalance': '0.00000000',\n",
      "                      'maintMargin': '0.00000000',\n",
      "                      '...': '......'},\n",
      "                     {'asset': 'NEAR',\n",
      "                      'walletBalance': '0.00000000',\n",
      "                      'unrealizedProfit': '0.00000000',\n",
      "                      'marginBalance': '0.00000000',\n",
      "                      'maintMargin': '0.00000000',\n",
      "                      '...': '......'},\n",
      "                     '......'],\n",
      "          'positions': [{'symbol': 'BCHUSD_240628',\n",
      "                         'initialMargin': '0',\n",
      "                         'maintMargin': '0',\n",
      "                         'unrealizedProfit': '0.00000000',\n",
      "                         'positionInitialMargin': '0',\n",
      "                         '...': '......'},\n",
      "                        {'symbol': 'BCHUSD_240628',\n",
      "                         'initialMargin': '0',\n",
      "                         'maintMargin': '0',\n",
      "                         'unrealizedProfit': '0.00000000',\n",
      "                         'positionInitialMargin': '0',\n",
      "                         '...': '......'},\n",
      "                        {'symbol': 'BCHUSD_240628',\n",
      "                         'initialMargin': '0',\n",
      "                         'maintMargin': '0',\n",
      "                         'unrealizedProfit': '0.00000000',\n",
      "                         'positionInitialMargin': '0',\n",
      "                         '...': '......'},\n",
      "                        {'symbol': 'NEARUSD_PERP',\n",
      "                         'initialMargin': '0',\n",
      "                         'maintMargin': '0',\n",
      "                         'unrealizedProfit': '0.00000000',\n",
      "                         'positionInitialMargin': '0',\n",
      "                         '...': '......'},\n",
      "                        {'symbol': 'NEARUSD_PERP',\n",
      "                         'initialMargin': '0',\n",
      "                         'maintMargin': '0',\n",
      "                         'unrealizedProfit': '0.00000000',\n",
      "                         'positionInitialMargin': '0',\n",
      "                         '...': '......'},\n",
      "                        '......']},\n",
      " 'msg': ''}\n"
     ]
    }
   ],
   "source": [
    "account_result = account.get_account()\n",
    "eprint(account_result)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d7cbf794",
   "metadata": {},
   "source": [
    "## 4. 获取单个产品余额 get_balance"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "65eb2cdc",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'code': 200,\n",
      " 'data': {'accountAlias': 'FzTiAusRuXmYTisR',\n",
      "          'asset': 'BTC',\n",
      "          'balance': '0.00148851',\n",
      "          'withdrawAvailable': '0.00148851',\n",
      "          'updateTime': 1706192301743,\n",
      "          'crossWalletBalance': '0.00148851',\n",
      "          'crossUnPnl': '0.00000000',\n",
      "          'availableBalance': '0.00148851'},\n",
      " 'msg': ''}\n"
     ]
    }
   ],
   "source": [
    "# 等价于下面代码：account.get_balance(symbol='BTCUSDT',base_asset='USDT')\n",
    "balance_result = account.get_balance(asset='BTC')\n",
    "eprint(balance_result)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e2bdd97c",
   "metadata": {},
   "source": [
    "## 5. 获取全部产品余额（列表格式） get_balances"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "bd7db4b7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'code': 200,\n",
      " 'data': [{'accountAlias': 'FzTiAusRuXmYTisR',\n",
      "           'asset': 'APE',\n",
      "           'balance': '0.00000000',\n",
      "           'withdrawAvailable': '0.00000000',\n",
      "           'updateTime': 0,\n",
      "           '...': '......'},\n",
      "          {'accountAlias': 'FzTiAusRuXmYTisR',\n",
      "           'asset': 'FTM',\n",
      "           'balance': '0.00000000',\n",
      "           'withdrawAvailable': '0.00000000',\n",
      "           'updateTime': 0,\n",
      "           '...': '......'},\n",
      "          {'accountAlias': 'FzTiAusRuXmYTisR',\n",
      "           'asset': 'TRX',\n",
      "           'balance': '0.00000000',\n",
      "           'withdrawAvailable': '0.00000000',\n",
      "           'updateTime': 0,\n",
      "           '...': '......'},\n",
      "          {'accountAlias': 'FzTiAusRuXmYTisR',\n",
      "           'asset': 'NEAR',\n",
      "           'balance': '0.00000000',\n",
      "           'withdrawAvailable': '0.00000000',\n",
      "           'updateTime': 0,\n",
      "           '...': '......'},\n",
      "          {'accountAlias': 'FzTiAusRuXmYTisR',\n",
      "           'asset': 'LUNA',\n",
      "           'balance': '0.00000000',\n",
      "           'withdrawAvailable': '0.00000000',\n",
      "           'updateTime': 0,\n",
      "           '...': '......'},\n",
      "          {'accountAlias': 'FzTiAusRuXmYTisR',\n",
      "           'asset': 'XRP',\n",
      "           'balance': '0.00000000',\n",
      "           'withdrawAvailable': '0.00000000',\n",
      "           'updateTime': 0,\n",
      "           '...': '......'},\n",
      "          {'accountAlias': 'FzTiAusRuXmYTisR',\n",
      "           'asset': 'ROSE',\n",
      "           'balance': '0.00000000',\n",
      "           'withdrawAvailable': '0.00000000',\n",
      "           'updateTime': 0,\n",
      "           '...': '......'},\n",
      "          {'accountAlias': 'FzTiAusRuXmYTisR',\n",
      "           'asset': 'LTC',\n",
      "           'balance': '0.00000000',\n",
      "           'withdrawAvailable': '0.00000000',\n",
      "           'updateTime': 0,\n",
      "           '...': '......'},\n",
      "          {'accountAlias': 'FzTiAusRuXmYTisR',\n",
      "           'asset': 'ALGO',\n",
      "           'balance': '0.00000000',\n",
      "           'withdrawAvailable': '0.00000000',\n",
      "           'updateTime': 0,\n",
      "           '...': '......'},\n",
      "          {'accountAlias': 'FzTiAusRuXmYTisR',\n",
      "           'asset': 'UNI',\n",
      "           'balance': '0.00000000',\n",
      "           'withdrawAvailable': '0.00000000',\n",
      "           'updateTime': 0,\n",
      "           '...': '......'},\n",
      "          {'accountAlias': 'FzTiAusRuXmYTisR',\n",
      "           'asset': 'AVAX',\n",
      "           'balance': '0.00000000',\n",
      "           'withdrawAvailable': '0.00000000',\n",
      "           'updateTime': 0,\n",
      "           '...': '......'},\n",
      "          {'accountAlias': 'FzTiAusRuXmYTisR',\n",
      "           'asset': 'ETH',\n",
      "           'balance': '0.03425805',\n",
      "           'withdrawAvailable': '0.02520429',\n",
      "           'updateTime': 1706192196816,\n",
      "           '...': '......'},\n",
      "          {'accountAlias': 'FzTiAusRuXmYTisR',\n",
      "           'asset': 'DOT',\n",
      "           'balance': '7.74147373',\n",
      "           'withdrawAvailable': '7.66410913',\n",
      "           'updateTime': 1706192466123,\n",
      "           '...': '......'},\n",
      "          {'accountAlias': 'FzTiAusRuXmYTisR',\n",
      "           'asset': 'EOS',\n",
      "           'balance': '0.00000000',\n",
      "           'withdrawAvailable': '0.00000000',\n",
      "           'updateTime': 0,\n",
      "           '...': '......'},\n",
      "          {'accountAlias': 'FzTiAusRuXmYTisR',\n",
      "           'asset': 'CHZ',\n",
      "           'balance': '0.00000000',\n",
      "           'withdrawAvailable': '0.00000000',\n",
      "           'updateTime': 0,\n",
      "           '...': '......'},\n",
      "          {'accountAlias': 'FzTiAusRuXmYTisR',\n",
      "           'asset': 'MATIC',\n",
      "           'balance': '0.00000000',\n",
      "           'withdrawAvailable': '0.00000000',\n",
      "           'updateTime': 0,\n",
      "           '...': '......'},\n",
      "          {'accountAlias': 'FzTiAusRuXmYTisR',\n",
      "           'asset': 'AAVE',\n",
      "           'balance': '0.00000000',\n",
      "           'withdrawAvailable': '0.00000000',\n",
      "           'updateTime': 0,\n",
      "           '...': '......'},\n",
      "          {'accountAlias': 'FzTiAusRuXmYTisR',\n",
      "           'asset': 'ICX',\n",
      "           'balance': '0.00000000',\n",
      "           'withdrawAvailable': '0.00000000',\n",
      "           'updateTime': 0,\n",
      "           '...': '......'},\n",
      "          {'accountAlias': 'FzTiAusRuXmYTisR',\n",
      "           'asset': 'RUNE',\n",
      "           'balance': '0.00000000',\n",
      "           'withdrawAvailable': '0.00000000',\n",
      "           'updateTime': 0,\n",
      "           '...': '......'},\n",
      "          {'accountAlias': 'FzTiAusRuXmYTisR',\n",
      "           'asset': 'CRV',\n",
      "           'balance': '0.00000000',\n",
      "           'withdrawAvailable': '0.00000000',\n",
      "           'updateTime': 0,\n",
      "           '...': '......'},\n",
      "          {'accountAlias': 'FzTiAusRuXmYTisR',\n",
      "           'asset': 'OP',\n",
      "           'balance': '0.00000000',\n",
      "           'withdrawAvailable': '0.00000000',\n",
      "           'updateTime': 0,\n",
      "           '...': '......'},\n",
      "          {'accountAlias': 'FzTiAusRuXmYTisR',\n",
      "           'asset': 'ENS',\n",
      "           'balance': '0.00000000',\n",
      "           'withdrawAvailable': '0.00000000',\n",
      "           'updateTime': 0,\n",
      "           '...': '......'},\n",
      "          {'accountAlias': 'FzTiAusRuXmYTisR',\n",
      "           'asset': 'AXS',\n",
      "           'balance': '0.00000000',\n",
      "           'withdrawAvailable': '0.00000000',\n",
      "           'updateTime': 0,\n",
      "           '...': '......'},\n",
      "          {'accountAlias': 'FzTiAusRuXmYTisR',\n",
      "           'asset': 'APT',\n",
      "           'balance': '0.00000000',\n",
      "           'withdrawAvailable': '0.00000000',\n",
      "           'updateTime': 0,\n",
      "           '...': '......'},\n",
      "          {'accountAlias': 'FzTiAusRuXmYTisR',\n",
      "           'asset': 'ZIL',\n",
      "           'balance': '0.00000000',\n",
      "           'withdrawAvailable': '0.00000000',\n",
      "           'updateTime': 0,\n",
      "           '...': '......'},\n",
      "          {'accountAlias': 'FzTiAusRuXmYTisR',\n",
      "           'asset': 'XLM',\n",
      "           'balance': '0.00000000',\n",
      "           'withdrawAvailable': '0.00000000',\n",
      "           'updateTime': 0,\n",
      "           '...': '......'},\n",
      "          {'accountAlias': 'FzTiAusRuXmYTisR',\n",
      "           'asset': 'BTC',\n",
      "           'balance': '0.00148851',\n",
      "           'withdrawAvailable': '0.00148851',\n",
      "           'updateTime': 1706192301743,\n",
      "           '...': '......'},\n",
      "          {'accountAlias': 'FzTiAusRuXmYTisR',\n",
      "           'asset': 'BCH',\n",
      "           'balance': '0.00000000',\n",
      "           'withdrawAvailable': '0.00000000',\n",
      "           'updateTime': 0,\n",
      "           '...': '......'},\n",
      "          {'accountAlias': 'FzTiAusRuXmYTisR',\n",
      "           'asset': 'THETA',\n",
      "           'balance': '0.00000000',\n",
      "           'withdrawAvailable': '0.00000000',\n",
      "           'updateTime': 0,\n",
      "           '...': '......'},\n",
      "          {'accountAlias': 'FzTiAusRuXmYTisR',\n",
      "           'asset': 'GALA',\n",
      "           'balance': '0.00000000',\n",
      "           'withdrawAvailable': '0.00000000',\n",
      "           'updateTime': 0,\n",
      "           '...': '......'},\n",
      "          '......'],\n",
      " 'msg': ''}\n"
     ]
    }
   ],
   "source": [
    "# 参数assets默认为[]，表示全部货币\n",
    "balances_result = account.get_balances()\n",
    "eprint(balances_result)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "0766324a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'code': 200,\n",
      " 'data': [{'accountAlias': 'FzTiAusRuXmYTisR',\n",
      "           'asset': 'BTC',\n",
      "           'balance': '0.00148851',\n",
      "           'withdrawAvailable': '0.00148851',\n",
      "           'updateTime': 1706192301743,\n",
      "           '...': '......'},\n",
      "          {'accountAlias': 'FzTiAusRuXmYTisR',\n",
      "           'asset': 'ETH',\n",
      "           'balance': '0.03425805',\n",
      "           'withdrawAvailable': '0.02520429',\n",
      "           'updateTime': 1706192196816,\n",
      "           '...': '......'}],\n",
      " 'msg': ''}\n"
     ]
    }
   ],
   "source": [
    "# 指定多个货币\n",
    "balances_result = account.get_balances(assets=['BTC', 'ETH'])\n",
    "eprint(balances_result)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e34b8d86",
   "metadata": {},
   "source": [
    "## 6. 获取全部产品余额（字典格式）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "a41d9ebe",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'code': 200,\n",
      " 'data': {'ATOM': {'accountAlias': 'FzTiAusRuXmYTisR',\n",
      "                   'asset': 'ATOM',\n",
      "                   'balance': '0.00000000',\n",
      "                   'withdrawAvailable': '0.00000000',\n",
      "                   'updateTime': 0,\n",
      "                   '...': '......'},\n",
      "          'LINK': {'accountAlias': 'FzTiAusRuXmYTisR',\n",
      "                   'asset': 'LINK',\n",
      "                   'balance': '0.00000000',\n",
      "                   'withdrawAvailable': '0.00000000',\n",
      "                   'updateTime': 0,\n",
      "                   '...': '......'},\n",
      "          'XRP': {'accountAlias': 'FzTiAusRuXmYTisR',\n",
      "                  'asset': 'XRP',\n",
      "                  'balance': '0.00000000',\n",
      "                  'withdrawAvailable': '0.00000000',\n",
      "                  'updateTime': 0,\n",
      "                  '...': '......'},\n",
      "          'LTC': {'accountAlias': 'FzTiAusRuXmYTisR',\n",
      "                  'asset': 'LTC',\n",
      "                  'balance': '0.00000000',\n",
      "                  'withdrawAvailable': '0.00000000',\n",
      "                  'updateTime': 0,\n",
      "                  '...': '......'},\n",
      "          'ROSE': {'accountAlias': 'FzTiAusRuXmYTisR',\n",
      "                   'asset': 'ROSE',\n",
      "                   'balance': '0.00000000',\n",
      "                   'withdrawAvailable': '0.00000000',\n",
      "                   'updateTime': 0,\n",
      "                   '...': '......'},\n",
      "          'XTZ': {'accountAlias': 'FzTiAusRuXmYTisR',\n",
      "                  'asset': 'XTZ',\n",
      "                  'balance': '0.00000000',\n",
      "                  'withdrawAvailable': '0.00000000',\n",
      "                  'updateTime': 0,\n",
      "                  '...': '......'},\n",
      "          'ADA': {'accountAlias': 'FzTiAusRuXmYTisR',\n",
      "                  'asset': 'ADA',\n",
      "                  'balance': '0.00000000',\n",
      "                  'withdrawAvailable': '0.00000000',\n",
      "                  'updateTime': 0,\n",
      "                  '...': '......'},\n",
      "          'APT': {'accountAlias': 'FzTiAusRuXmYTisR',\n",
      "                  'asset': 'APT',\n",
      "                  'balance': '0.00000000',\n",
      "                  'withdrawAvailable': '0.00000000',\n",
      "                  'updateTime': 0,\n",
      "                  '...': '......'},\n",
      "          'BCH': {'accountAlias': 'FzTiAusRuXmYTisR',\n",
      "                  'asset': 'BCH',\n",
      "                  'balance': '0.00000000',\n",
      "                  'withdrawAvailable': '0.00000000',\n",
      "                  'updateTime': 0,\n",
      "                  '...': '......'},\n",
      "          'ALGO': {'accountAlias': 'FzTiAusRuXmYTisR',\n",
      "                   'asset': 'ALGO',\n",
      "                   'balance': '0.00000000',\n",
      "                   'withdrawAvailable': '0.00000000',\n",
      "                   'updateTime': 0,\n",
      "                   '...': '......'},\n",
      "          'BTC': {'accountAlias': 'FzTiAusRuXmYTisR',\n",
      "                  'asset': 'BTC',\n",
      "                  'balance': '0.00148851',\n",
      "                  'withdrawAvailable': '0.00148851',\n",
      "                  'updateTime': 1706192301743,\n",
      "                  '...': '......'},\n",
      "          'DOGE': {'accountAlias': 'FzTiAusRuXmYTisR',\n",
      "                   'asset': 'DOGE',\n",
      "                   'balance': '0.00000000',\n",
      "                   'withdrawAvailable': '0.00000000',\n",
      "                   'updateTime': 0,\n",
      "                   '...': '......'},\n",
      "          'UNI': {'accountAlias': 'FzTiAusRuXmYTisR',\n",
      "                  'asset': 'UNI',\n",
      "                  'balance': '0.00000000',\n",
      "                  'withdrawAvailable': '0.00000000',\n",
      "                  'updateTime': 0,\n",
      "                  '...': '......'},\n",
      "          'XLM': {'accountAlias': 'FzTiAusRuXmYTisR',\n",
      "                  'asset': 'XLM',\n",
      "                  'balance': '0.00000000',\n",
      "                  'withdrawAvailable': '0.00000000',\n",
      "                  'updateTime': 0,\n",
      "                  '...': '......'},\n",
      "          'SOL': {'accountAlias': 'FzTiAusRuXmYTisR',\n",
      "                  'asset': 'SOL',\n",
      "                  'balance': '0.00000000',\n",
      "                  'withdrawAvailable': '0.00000000',\n",
      "                  'updateTime': 0,\n",
      "                  '...': '......'},\n",
      "          'MANA': {'accountAlias': 'FzTiAusRuXmYTisR',\n",
      "                   'asset': 'MANA',\n",
      "                   'balance': '0.00000000',\n",
      "                   'withdrawAvailable': '0.00000000',\n",
      "                   'updateTime': 0,\n",
      "                   '...': '......'},\n",
      "          'SAND': {'accountAlias': 'FzTiAusRuXmYTisR',\n",
      "                   'asset': 'SAND',\n",
      "                   'balance': '0.00000000',\n",
      "                   'withdrawAvailable': '0.00000000',\n",
      "                   'updateTime': 0,\n",
      "                   '...': '......'},\n",
      "          'VET': {'accountAlias': 'FzTiAusRuXmYTisR',\n",
      "                  'asset': 'VET',\n",
      "                  'balance': '0.00000000',\n",
      "                  'withdrawAvailable': '0.00000000',\n",
      "                  'updateTime': 0,\n",
      "                  '...': '......'},\n",
      "          'GALA': {'accountAlias': 'FzTiAusRuXmYTisR',\n",
      "                   'asset': 'GALA',\n",
      "                   'balance': '0.00000000',\n",
      "                   'withdrawAvailable': '0.00000000',\n",
      "                   'updateTime': 0,\n",
      "                   '...': '......'},\n",
      "          'ETC': {'accountAlias': 'FzTiAusRuXmYTisR',\n",
      "                  'asset': 'ETC',\n",
      "                  'balance': '0.00000000',\n",
      "                  'withdrawAvailable': '0.00000000',\n",
      "                  'updateTime': 0,\n",
      "                  '...': '......'},\n",
      "          'APE': {'accountAlias': 'FzTiAusRuXmYTisR',\n",
      "                  'asset': 'APE',\n",
      "                  'balance': '0.00000000',\n",
      "                  'withdrawAvailable': '0.00000000',\n",
      "                  'updateTime': 0,\n",
      "                  '...': '......'},\n",
      "          'MATIC': {'accountAlias': 'FzTiAusRuXmYTisR',\n",
      "                    'asset': 'MATIC',\n",
      "                    'balance': '0.00000000',\n",
      "                    'withdrawAvailable': '0.00000000',\n",
      "                    'updateTime': 0,\n",
      "                    '...': '......'},\n",
      "          'AAVE': {'accountAlias': 'FzTiAusRuXmYTisR',\n",
      "                   'asset': 'AAVE',\n",
      "                   'balance': '0.00000000',\n",
      "                   'withdrawAvailable': '0.00000000',\n",
      "                   'updateTime': 0,\n",
      "                   '...': '......'},\n",
      "          'XMR': {'accountAlias': 'FzTiAusRuXmYTisR',\n",
      "                  'asset': 'XMR',\n",
      "                  'balance': '0.00000000',\n",
      "                  'withdrawAvailable': '0.00000000',\n",
      "                  'updateTime': 0,\n",
      "                  '...': '......'},\n",
      "          'DOT': {'accountAlias': 'FzTiAusRuXmYTisR',\n",
      "                  'asset': 'DOT',\n",
      "                  'balance': '7.74147373',\n",
      "                  'withdrawAvailable': '7.66361129',\n",
      "                  'updateTime': 1706192466123,\n",
      "                  '...': '......'},\n",
      "          'GMT': {'accountAlias': 'FzTiAusRuXmYTisR',\n",
      "                  'asset': 'GMT',\n",
      "                  'balance': '0.00000000',\n",
      "                  'withdrawAvailable': '0.00000000',\n",
      "                  'updateTime': 0,\n",
      "                  '...': '......'},\n",
      "          'OP': {'accountAlias': 'FzTiAusRuXmYTisR',\n",
      "                 'asset': 'OP',\n",
      "                 'balance': '0.00000000',\n",
      "                 'withdrawAvailable': '0.00000000',\n",
      "                 'updateTime': 0,\n",
      "                 '...': '......'},\n",
      "          'ETH': {'accountAlias': 'FzTiAusRuXmYTisR',\n",
      "                  'asset': 'ETH',\n",
      "                  'balance': '0.03425805',\n",
      "                  'withdrawAvailable': '0.02520429',\n",
      "                  'updateTime': 1706192196816,\n",
      "                  '...': '......'},\n",
      "          'TRX': {'accountAlias': 'FzTiAusRuXmYTisR',\n",
      "                  'asset': 'TRX',\n",
      "                  'balance': '0.00000000',\n",
      "                  'withdrawAvailable': '0.00000000',\n",
      "                  'updateTime': 0,\n",
      "                  '...': '......'},\n",
      "          'FIL': {'accountAlias': 'FzTiAusRuXmYTisR',\n",
      "                  'asset': 'FIL',\n",
      "                  'balance': '0.00000000',\n",
      "                  'withdrawAvailable': '0.00000000',\n",
      "                  'updateTime': 0,\n",
      "                  '...': '......'},\n",
      "          'CRV': {'accountAlias': 'FzTiAusRuXmYTisR',\n",
      "                  'asset': 'CRV',\n",
      "                  'balance': '0.00000000',\n",
      "                  'withdrawAvailable': '0.00000000',\n",
      "                  'updateTime': 0,\n",
      "                  '...': '......'},\n",
      "          '...': '......'},\n",
      " 'msg': ''}\n"
     ]
    }
   ],
   "source": [
    "# 参数assets默认为[]，表示全部货币\n",
    "balancesMap_result = account.get_balancesMap()\n",
    "eprint(balancesMap_result)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "b5ebd569",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'code': 200,\n",
      " 'data': {'ETH': {'accountAlias': 'FzTiAusRuXmYTisR',\n",
      "                  'asset': 'ETH',\n",
      "                  'balance': '0.03425805',\n",
      "                  'withdrawAvailable': '0.02520429',\n",
      "                  'updateTime': 1706192196816,\n",
      "                  '...': '......'},\n",
      "          'BTC': {'accountAlias': 'FzTiAusRuXmYTisR',\n",
      "                  'asset': 'BTC',\n",
      "                  'balance': '0.00148851',\n",
      "                  'withdrawAvailable': '0.00148851',\n",
      "                  'updateTime': 1706192301743,\n",
      "                  '...': '......'}},\n",
      " 'msg': ''}\n"
     ]
    }
   ],
   "source": [
    "# 指定多个货币\n",
    "balancesMap_result = account.get_balancesMap(assets=['BTC', 'ETH'])\n",
    "eprint(balancesMap_result)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "12e21085",
   "metadata": {},
   "source": [
    "## 7. 调整开仓杠杆 set_leverage"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "ef7cfe31",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'code': 200, 'data': {'symbol': 'BTCUSD_PERP', 'leverage': 2, 'maxQty': '1500'}, 'msg': ''}\n"
     ]
    }
   ],
   "source": [
    "leverage_result = account.set_leverage(symbol='BTCUSD_PERP', leverage=2)\n",
    "eprint(leverage_result)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0de2fb68",
   "metadata": {},
   "source": [
    "## 8. 更改持仓模式 set_marginType"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "a8ad0d4f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'code': 200, 'msg': 'success'}\n"
     ]
    }
   ],
   "source": [
    "marginType_result = account.set_marginType(symbol='BTCUSD_PERP', marginType='CROSSED')\n",
    "eprint(marginType_result)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "7c2a5064",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'code': 200, 'msg': 'success'}\n"
     ]
    }
   ],
   "source": [
    "marginType_result = account.set_marginType(symbol='BTCUSD_PERP', marginType='ISOLATED')\n",
    "eprint(marginType_result)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2aa3e0c9",
   "metadata": {},
   "source": [
    "## 9. 获取单个产品的持仓信息 get_position"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "718df537",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'code': 200,\n",
      " 'data': {'CROSSED': {'LONG': {}, 'SHORT': {}},\n",
      "          'ISOLATED': {'LONG': {'symbol': 'ETHUSD_PERP',\n",
      "                                'initialMargin': '0.00452979',\n",
      "                                'maintMargin': '0.00002264',\n",
      "                                'unrealizedProfit': '0.00000075',\n",
      "                                'positionInitialMargin': '0.00452979',\n",
      "                                'openOrderInitialMargin': '0',\n",
      "                                'leverage': '1',\n",
      "                                'isolated': True,\n",
      "                                'positionSide': 'LONG',\n",
      "                                'entryPrice': '2207.22999998',\n",
      "                                'maxQty': '50000',\n",
      "                                'notionalValue': '0.00452980',\n",
      "                                'isolatedWallet': '0.00452950',\n",
      "                                'updateTime': 1706192161738,\n",
      "                                'positionAmt': '1',\n",
      "                                'breakEvenPrice': '2208.33361497'},\n",
      "                       'SHORT': {}}},\n",
      " 'msg': ''}\n"
     ]
    }
   ],
   "source": [
    "position_result = account.get_position(symbol='ETHUSD_PERP')\n",
    "eprint(position_result)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8c384430",
   "metadata": {},
   "source": [
    "## 10. 获取全部产品的持仓信息（列表格式） get_positions"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "5675740d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'code': 200,\n",
      " 'data': {'CROSSED': {'LONG': [{'symbol': 'DOTUSD_PERP',\n",
      "                                'initialMargin': '0.07763684',\n",
      "                                'maintMargin': '0.03881842',\n",
      "                                'unrealizedProfit': '-0.00018287',\n",
      "                                'positionInitialMargin': '0.07763684',\n",
      "                                'openOrderInitialMargin': '0',\n",
      "                                'leverage': '20',\n",
      "                                'isolated': False,\n",
      "                                'positionSide': 'LONG',\n",
      "                                'entryPrice': '6.44099999',\n",
      "                                'maxQty': '25000',\n",
      "                                'notionalValue': '1.55273682',\n",
      "                                'isolatedWallet': '0',\n",
      "                                'updateTime': 1706192466123,\n",
      "                                'positionAmt': '1',\n",
      "                                'breakEvenPrice': '6.44422049'},\n",
      "                               {'symbol': 'BNBUSD_PERP',\n",
      "                                'initialMargin': '0.00170525',\n",
      "                                'maintMargin': '0.00085262',\n",
      "                                'unrealizedProfit': '-0.00004176',\n",
      "                                'positionInitialMargin': '0.00170525',\n",
      "                                'openOrderInitialMargin': '0',\n",
      "                                'leverage': '20',\n",
      "                                'isolated': False,\n",
      "                                'positionSide': 'LONG',\n",
      "                                'entryPrice': '293.57000000',\n",
      "                                'maxQty': '2000',\n",
      "                                'notionalValue': '0.03410518',\n",
      "                                'isolatedWallet': '0',\n",
      "                                'updateTime': 1706192408299,\n",
      "                                'positionAmt': '1',\n",
      "                                'breakEvenPrice': '293.71678499'}],\n",
      "                      'SHORT': []},\n",
      "          'ISOLATED': {'LONG': [{'symbol': 'ETHUSD_PERP',\n",
      "                                 'initialMargin': '0.00452961',\n",
      "                                 'maintMargin': '0.00002264',\n",
      "                                 'unrealizedProfit': '0.00000094',\n",
      "                                 'positionInitialMargin': '0.00452961',\n",
      "                                 'openOrderInitialMargin': '0',\n",
      "                                 'leverage': '1',\n",
      "                                 'isolated': True,\n",
      "                                 'positionSide': 'LONG',\n",
      "                                 'entryPrice': '2207.22999998',\n",
      "                                 'maxQty': '50000',\n",
      "                                 'notionalValue': '0.00452961',\n",
      "                                 'isolatedWallet': '0.00452950',\n",
      "                                 'updateTime': 1706192161738,\n",
      "                                 'positionAmt': '1',\n",
      "                                 'breakEvenPrice': '2208.33361497'}],\n",
      "                       'SHORT': []}},\n",
      " 'msg': ''}\n"
     ]
    }
   ],
   "source": [
    "# 参数symbols默认为[]，表示全部产品\n",
    "positions_result = account.get_positions()\n",
    "eprint(positions_result)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "61f3a69f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'code': 200,\n",
      " 'data': {'CROSSED': {'LONG': [{'symbol': 'BNBUSD_PERP',\n",
      "                                'initialMargin': '0.00170528',\n",
      "                                'maintMargin': '0.00085264',\n",
      "                                'unrealizedProfit': '-0.00004235',\n",
      "                                'positionInitialMargin': '0.00170528',\n",
      "                                'openOrderInitialMargin': '0',\n",
      "                                'leverage': '20',\n",
      "                                'isolated': False,\n",
      "                                'positionSide': 'LONG',\n",
      "                                'entryPrice': '293.57000000',\n",
      "                                'maxQty': '2000',\n",
      "                                'notionalValue': '0.03410577',\n",
      "                                'isolatedWallet': '0',\n",
      "                                'updateTime': 1706192408299,\n",
      "                                'positionAmt': '1',\n",
      "                                'breakEvenPrice': '293.71678499'}],\n",
      "                      'SHORT': []},\n",
      "          'ISOLATED': {'LONG': [{'symbol': 'ETHUSD_PERP',\n",
      "                                 'initialMargin': '0.00452996',\n",
      "                                 'maintMargin': '0.00002264',\n",
      "                                 'unrealizedProfit': '0.00000060',\n",
      "                                 'positionInitialMargin': '0.00452996',\n",
      "                                 'openOrderInitialMargin': '0',\n",
      "                                 'leverage': '1',\n",
      "                                 'isolated': True,\n",
      "                                 'positionSide': 'LONG',\n",
      "                                 'entryPrice': '2207.22999998',\n",
      "                                 'maxQty': '50000',\n",
      "                                 'notionalValue': '0.00452996',\n",
      "                                 'isolatedWallet': '0.00452950',\n",
      "                                 'updateTime': 1706192161738,\n",
      "                                 'positionAmt': '1',\n",
      "                                 'breakEvenPrice': '2208.33361497'}],\n",
      "                       'SHORT': []}},\n",
      " 'msg': ''}\n"
     ]
    }
   ],
   "source": [
    "# 指定多个产品\n",
    "positions_result = account.get_positions(symbols=['ETHUSD_PERP', 'BNBUSD_PERP'])\n",
    "eprint(positions_result)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3a2c676d",
   "metadata": {},
   "source": [
    "## 11. 获取全部产品的持仓信息（字典格式） get_positionsMap"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "8c360633",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'code': 200,\n",
      " 'data': {'CROSSED': {'LONG': {'BNBUSD_PERP': {'symbol': 'BNBUSD_PERP',\n",
      "                                               'initialMargin': '0.00170497',\n",
      "                                               'maintMargin': '0.00085248',\n",
      "                                               'unrealizedProfit': '-0.00003600',\n",
      "                                               'positionInitialMargin': '0.00170497',\n",
      "                                               'openOrderInitialMargin': '0',\n",
      "                                               'leverage': '20',\n",
      "                                               'isolated': False,\n",
      "                                               'positionSide': 'LONG',\n",
      "                                               'entryPrice': '293.57000000',\n",
      "                                               'maxQty': '2000',\n",
      "                                               'notionalValue': '0.03409943',\n",
      "                                               'isolatedWallet': '0',\n",
      "                                               'updateTime': 1706192408299,\n",
      "                                               'positionAmt': '1',\n",
      "                                               'breakEvenPrice': '293.71678499'},\n",
      "                               'DOTUSD_PERP': {'symbol': 'DOTUSD_PERP',\n",
      "                                               'initialMargin': '0.07766104',\n",
      "                                               'maintMargin': '0.03883052',\n",
      "                                               'unrealizedProfit': '-0.00066692',\n",
      "                                               'positionInitialMargin': '0.07766104',\n",
      "                                               'openOrderInitialMargin': '0',\n",
      "                                               'leverage': '20',\n",
      "                                               'isolated': False,\n",
      "                                               'positionSide': 'LONG',\n",
      "                                               'entryPrice': '6.44099999',\n",
      "                                               'maxQty': '25000',\n",
      "                                               'notionalValue': '1.55322087',\n",
      "                                               'isolatedWallet': '0',\n",
      "                                               'updateTime': 1706192466123,\n",
      "                                               'positionAmt': '1',\n",
      "                                               'breakEvenPrice': '6.44422049'}},\n",
      "                      'SHORT': {}},\n",
      "          'ISOLATED': {'LONG': {'ETHUSD_PERP': {'symbol': 'ETHUSD_PERP',\n",
      "                                                'initialMargin': '0.00452974',\n",
      "                                                'maintMargin': '0.00002264',\n",
      "                                                'unrealizedProfit': '0.00000081',\n",
      "                                                'positionInitialMargin': '0.00452974',\n",
      "                                                'openOrderInitialMargin': '0',\n",
      "                                                'leverage': '1',\n",
      "                                                'isolated': True,\n",
      "                                                'positionSide': 'LONG',\n",
      "                                                'entryPrice': '2207.22999998',\n",
      "                                                'maxQty': '50000',\n",
      "                                                'notionalValue': '0.00452974',\n",
      "                                                'isolatedWallet': '0.00452950',\n",
      "                                                'updateTime': 1706192161738,\n",
      "                                                'positionAmt': '1',\n",
      "                                                'breakEvenPrice': '2208.33361497'}},\n",
      "                       'SHORT': {}}},\n",
      " 'msg': ''}\n"
     ]
    }
   ],
   "source": [
    "# 参数symbols默认为[]，表示全部产品\n",
    "positionsMap_result = account.get_positionsMap()\n",
    "eprint(positionsMap_result)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "01d9c32e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'code': 200,\n",
      " 'data': {'CROSSED': {'LONG': {'BNBUSD_PERP': {'symbol': 'BNBUSD_PERP',\n",
      "                                               'initialMargin': '0.00170483',\n",
      "                                               'maintMargin': '0.00085241',\n",
      "                                               'unrealizedProfit': '-0.00003326',\n",
      "                                               'positionInitialMargin': '0.00170483',\n",
      "                                               'openOrderInitialMargin': '0',\n",
      "                                               'leverage': '20',\n",
      "                                               'isolated': False,\n",
      "                                               'positionSide': 'LONG',\n",
      "                                               'entryPrice': '293.57000000',\n",
      "                                               'maxQty': '2000',\n",
      "                                               'notionalValue': '0.03409668',\n",
      "                                               'isolatedWallet': '0',\n",
      "                                               'updateTime': 1706192408299,\n",
      "                                               'positionAmt': '1',\n",
      "                                               'breakEvenPrice': '293.71678499'}},\n",
      "                      'SHORT': {}},\n",
      "          'ISOLATED': {'LONG': {'ETHUSD_PERP': {'symbol': 'ETHUSD_PERP',\n",
      "                                                'initialMargin': '0.00452934',\n",
      "                                                'maintMargin': '0.00002264',\n",
      "                                                'unrealizedProfit': '0.00000122',\n",
      "                                                'positionInitialMargin': '0.00452934',\n",
      "                                                'openOrderInitialMargin': '0',\n",
      "                                                'leverage': '1',\n",
      "                                                'isolated': True,\n",
      "                                                'positionSide': 'LONG',\n",
      "                                                'entryPrice': '2207.22999998',\n",
      "                                                'maxQty': '50000',\n",
      "                                                'notionalValue': '0.00452934',\n",
      "                                                'isolatedWallet': '0.00452950',\n",
      "                                                'updateTime': 1706192161738,\n",
      "                                                'positionAmt': '1',\n",
      "                                                'breakEvenPrice': '2208.33361497'}},\n",
      "                       'SHORT': {}}},\n",
      " 'msg': ''}\n"
     ]
    }
   ],
   "source": [
    "# 指定多个产品\n",
    "positionsMap_result = account.get_positionsMap(symbols=['ETHUSD_PERP', 'BNBUSD_PERP'])\n",
    "eprint(positionsMap_result)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
